package Demo03.Demo02;
 
public class Singleton1 {
    public static void main(String[] args) {
        Singleton instance = Singleton.getInstance();
        Singleton instance2 = Singleton.getInstance();
        if (instance==instance2){
            System.out.println("yes");
        }else {
            System.out.println("no");
        }
 
    }
}
 
class Singleton {
    //私有化构造器防止new
    private Singleton(){
 
    }
    //本类内部创建对象实例
    private final  static Singleton instance = new Singleton();
 
 
    public static Singleton getInstance(){
        return instance;
    }
}